package com.example.bookstore.api

import com.example.bookstore.response.SuccessResponse
import com.example.bookstore.service.UserService
import com.example.bookstore.validate.UserRegisterValidate
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RestController

/**
 * Created by IntelliJ IDEA.
 * User: lvshe
 * Date: 2019/8/13
 * Time: 18:51
 */
@Api(tags = ["session"], basePath = "/api/session")
@RestController
class SessionController {

    @Autowired
    private lateinit var userService: UserService

    @ApiOperation("注册", notes = "注册用户，请求为Json格式")
    @PostMapping("/api/session/new")
    fun register(@RequestBody @Validated userRegisterValidate: UserRegisterValidate): SuccessResponse {
          userService.registerUser(userRegisterValidate.toUserEntity())
        return SuccessResponse("注册成功")
    }

}